#include "Comm.hpp"
#include "Fifo.hpp"
int main()
{
    //0.引入管道
    Sync syn;
    syn.OpenWriteOrDie();

    //1.获取key
    int shmkey = GetShmKeyOrDie();
    cout << "key: " << ToHex(shmkey) << endl;

    //2.获取共享内存
    int shmid = GetShm(shmkey, defaultsize);
    cout << "shmid: " << shmid << endl;
    //sleep(2);

    //3.挂接shm
    char* addr = (char*)ShmAttach(shmid);
    cout  << "shm attach success, " << "addr: " << ToHex((uint64_t)addr) << endl;
   // sleep(5);



    //可以通信了
    for (char c = 'A'; c <= 'Z'; c++)   //read.writh->系统掉用; shm直接写入内容
    {
        addr[c - 'A'] = c;
        syn.Wakeup();
        sleep(1);   //间隔1s唤醒一次
    }



    //4.去关联
    ShmDetach(addr);
    cout << "shm detach success, addr: " << ToHex((uint64_t)addr) << endl;
    //sleep(10);
    return 0;
}